package com.py.credit.service.impl;

import java.io.File;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.py.credit.dao.UserManagerDao;
import com.py.credit.entity.Firm;
import com.py.credit.service.UserManagerService;
import com.py.credit.utils.SQLBuilder;
import com.py.framework.core.common.Page;

@Service
public class UserManagerServiceImpl implements UserManagerService {
	@Autowired
	private UserManagerDao userManagerDao;

	@Override
	public List<Map<String, Object>> selectAllUserInfromationForPage(String type, List<String> columns,
			String[] additionalColumns, String condition, Page page) {
		List<String> conditions = SQLBuilder.createConditionSql(condition);
		List<Map<String, Object>> userList = userManagerDao.selectAllUserInfromationByConditionForPage(type, columns,
				additionalColumns, conditions, page);
		return userList;
	}

	@Override
	public void updateFreeUnlockStatus(String zhzt, int id) {
		userManagerDao.updateFreeUnlockStatus(zhzt, id);
	}

	@Override
	public void updateUserPassword(String password, int id) {

		userManagerDao.updateUserPassword(password, id);
	}

	@Override
	public Map<String, Object> selectOneUserInformation(int id) {
		Map<String, Object> userMap = userManagerDao.selectOneUserInformation(id);

		String zjwjurl = (String) userMap.get("dirPath") + File.separator + userMap.get("zjwj");
		String sfzwj_frontUrl = (String) userMap.get("dirPath") + File.separator + userMap.get("sfzwj_front");
		String sfzwj_backUrl = (String) userMap.get("dirPath") + File.separator + userMap.get("sfzwj_back");
		userMap.put("zjwjurl", zjwjurl);
		userMap.put("sfzwj_frontUrl", sfzwj_frontUrl);
		userMap.put("sfzwj_backUrl", sfzwj_backUrl);
		return userMap;
	}

	@Override
	public void insertXypjUserCheck(String userid, String shzt, String shyj, String shuser) {
		userManagerDao.insertXypjUserCheck(userid, shzt, shyj, shuser);
	}

	@Override
	public List<Map<String, String>> selectUserCheck(String userid) {
		List<Map<String, String>> userList = userManagerDao.selectUserCheck(userid);
		return userList;
	}

	@Transactional
	@Override
	public void updateUserShzt(String shzt, String shyi, String shuser, String id) {
		userManagerDao.updateUserShzt(shzt, id);
		userManagerDao.insertXypjUserCheck(id, shzt, shyi, shuser);
	}

	@Override
	public List<Firm> getAuthorizedFirms(String idcardNumber, Page page) {

		return userManagerDao.selectFirmInfoByPage(idcardNumber, page);

	}

	@Override
	public String getIdCardNumber(String username, String type) {

		return userManagerDao.selectIdcardNumber(username, type);
	}

}
